home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / as02.arc / MOVFILES.ASM < prev    next >
Assembly Source File  |  1984-10-10  |  7KB  |  211 lines

  1. ;    movfiles.asm   10/9/84   gwf
  2. ;This routine is called from a basic program. (example below). It finds
  3. ; all files which match the given mask in the oldpath directory and moves
  4. ; them to the new path directory. The name is not changed.
  5. ;
  6. ;     10 COLOR 7,1:CLS
  7. ;     20 INPUT"OLD PATH (Include drive letter and :) ",OLDPATH$
  8. ;     25 if len(oldpath$)>17 then print"Cannot be that long":goto 20
  9. ;     30 INPUT"NEW PATH (Include drive letter and :) ",NEWPATH$
  10. ;     35 if len(newpath$)>17 then print"Cannot be that long":goto 30
  11. ;     40 INPUT"MASK ",MASK$
  12. ;     45 mask$=mask$+chr$(0)         'IMPORTANT TO DO THIS
  13. ;     50 PRINT"JUST BEFORE CALL ";TIME$
  14. ;     60 CALL MOVFILES(OLDPATH$,NEWPATH$,MASK$)
  15. ;     70 PRINT"JUST AFTER CALL  ";TIME$
  16. ;
  17. find_first equ    4eh    ;Find first match function call
  18. find_next  equ    4fh    ;Find next match function call
  19. re_name equ    56h    ;Rename a file function call
  20. get_dta equ    2fh    ;Get current disk transfer area function call
  21. doscall equ    21h    ;DOS interrupt number
  22. ;
  23. dgroup    group    datarea
  24. datarea segment para public 'DATA'
  25. ;
  26. o_pa_len  dw      ?          ;length of old path string
  27. o_path      db      20h dup('\')    ;   actual old path string it will end in '\'
  28. o_off_set dw      ?          ;this is offset to end of old path
  29. ;
  30. n_pa_len  dw      ?          ;length of new path string
  31. n_path      db      20h dup('\')    ;   actual new path string it will end in '\'
  32. n_off_set dw      ?          ;this is offset to end of new path file
  33. ;
  34. datarea ends
  35. ;
  36. cseg      segment 'CODE'
  37.       assume  cs:cseg,ds:datarea
  38.       public  MOVFILES
  39. MOVFILES  proc      far
  40.     push    bp        ;save BP for basic
  41.     mov    bp,sp        ;set base for parm list
  42.     push    ds        ;save DS for basic
  43.     push    es        ;save ES for basic
  44.     mov    ax,datarea    ;local data space
  45.     mov    ds,ax        ;now DS is the local space
  46. ;
  47. ;
  48.     mov    si,ss:[bp+10]    ;get addr of old path string length
  49.     mov    ax,es:[si]    ;get len of old path string
  50.     mov   o_pa_len,ax
  51.     mov    ax,es:[si+2]    ;get address of old path string
  52. ;
  53. ;   set up address of string from basic and local data area string
  54. ;
  55.     mov    si,ax        ;set address of string in si
  56.     lea    di,o_path    ;load address of local data area string
  57.     mov    cx,o_pa_len    ;set loop counter to length of string
  58.     call    mov_it        ;move string to local area
  59. ;
  60. ;Append the mask to the end of the old path. (for the find first call)
  61.     mov    ax,offset o_path;we need to compute the address where the
  62.     add    ax,o_pa_len    ; the append will begin. Offset plus length
  63.     add    ax,1        ;    plus 1 for the '\'.
  64.     mov    o_off_set,ax    ; save for future reference
  65.     mov    di,ax        ;load address of local data area string
  66. ;
  67.     mov    si,ss:[bp+6]    ;get addr of mask string length
  68.     mov    cx,es:[si]    ;get len of mask string
  69.     mov    ax,es:[si+2]    ;get address of mask string
  70. ;
  71. ;   set up address of string from basic and local data area string
  72. ;
  73.     mov    si,ax        ;set address of string in si
  74.     call    mov_it        ;move string to local area
  75. ;
  76.  
  77.     mov    si,ss:[bp+8]    ;get addr of new path string length
  78.     mov    ax,es:[si]    ;get len of new path string
  79.     mov   n_pa_len,ax
  80.     mov    ax,es:[si+2]    ;get address of new path string
  81. ;
  82. ;   set up address of string from basic and local data area string
  83. ;
  84.     mov    si,ax        ;set address of string in si
  85.     lea    di,n_path    ;load address of local data area string
  86.     mov    cx,n_pa_len    ;set loop counter to length of string
  87.     call    mov_it        ;move string to local area
  88. ;
  89. ;
  90.     mov    ax,offset n_path;we need to compute the address where the
  91.     add    ax,n_pa_len    ; the append will begin. Offset plus length
  92.     add    ax,1        ;    plus 1 for the '\'.
  93.     mov    n_off_set,ax
  94. ;
  95. ;Now all parameters are local. It is time to have local ES.
  96. ;    mov    ax,datarea    ;local data space
  97. ;    mov    es,ax        ;now ES is the local space
  98. ;    assume    es:datarea
  99. ;
  100. ;AT THIS POINT IN THE PROGRAM WE ARE ALL SET TO DO THE GET FIRST FUNCTION CALL.
  101. ;We will find the first file name in the old directory which matches on the
  102. ;mask. We will move it to the new path w/o changing its name. We will then
  103. ;invoke the find next call until all are moved.
  104. ;
  105.     mov    ah,find_first    ;find first match function number
  106.     mov    cx,16h        ;set attribute byte to match any file
  107.     mov  dx,offset o_path    ;DS:DX points to the absolute file name
  108.                 ;  which we want to match
  109.     int    doscall     ;Call DOS
  110.  
  111.  
  112.     mov    ah,get_dta    ;get disk transf. area func. number
  113.     int    doscall     ;Call DOS
  114.  
  115. ;ES:BX points to current disk transfer area
  116.     mov    si,bx        ;location of the DTA
  117.     add    si,30d        ;location of the name found
  118. ;Move into old path.
  119.     mov    di,o_off_set    ;address of where name should start in old path
  120.     mov    cx,13d        ; 8part name, period, 3 place extension, and 0h
  121.     call    mov_it        ;    actually move it there
  122.  
  123. ;Move into new path.
  124.     mov    si,bx        ;location of the DTA
  125.     add    si,30d        ;location of the name found
  126.     mov    di,n_off_set    ;address of where name should start in new path
  127.     mov    cx,13d        ; 8part name, period, 3 place extension, and 0h
  128.     call    mov_it        ;    actually move it there
  129.  
  130. ;We will now rename this first found before we enter the find next loop
  131.  
  132. ;DS:DX points to old name
  133.     mov    dx,offset o_path;location of old name put in DX
  134. ;ES:DI points to new name
  135.     push    es        ;save es for later
  136.     push    ds        ;need es to be equal to ds
  137.     pop    es        ;   now it is
  138.     mov   di,offset n_path    ;location of new name put in DI
  139.  
  140.     mov    ah,re_name    ;rename function number
  141.     int    doscall     ;Call DOS
  142.     pop    es        ;restore es for the next DTA.
  143.  
  144. ;The first matching file if the old path has been found and moved.
  145. ;Now we will take care of all others in the do_next_old loop.
  146.  
  147. do_next_old:
  148.     mov    ah,find_next    ;Find next function call
  149.     int    doscall     ;Call DOS
  150.     cmp    ax,12h        ;18d is the no more files error code
  151.     je    exit        ;    leave if no more files
  152.  
  153.     mov    ah,get_dta    ;get disk transf. area func. number
  154.     int    doscall     ;Call DOS
  155.  
  156. ;ES:BX points to current disk transfer area
  157.     mov    si,bx        ;location of the DTA
  158.     add    si,30d        ;location of the name found
  159. ;Move into old path.
  160.     mov    di,o_off_set    ;address of where name should start in old path
  161.     mov    cx,13d        ; 8part name, period, 3 place extension, and 0h
  162.     call    mov_it        ;    actually move it there
  163.  
  164. ;Move into new path.
  165.     mov    si,bx        ;location of the DTA
  166.     add    si,30d        ;location of the name found
  167.     mov    di,n_off_set    ;address of where name should start in new path
  168.     mov    cx,13d        ; 8part name, period, 3 place extension, and 0h
  169.     call    mov_it        ;    actually move it there
  170.  
  171. ;We will now rename this file before we jump back to the find next loop
  172.  
  173. ;DS:DX points to old name
  174.     mov    dx,offset o_path;location of old name put in DX
  175. ;ES:DI points to new name
  176.     push    es        ;save es for later
  177.     push    ds        ;need es to be equal to ds
  178.     pop    es        ;   now it is
  179.     mov   di,offset n_path    ;location of new name put in DI
  180.  
  181.     mov    ah,re_name    ;rename function number
  182.     int    doscall     ;Call DOS
  183.     pop    es        ;restore es for the next DTA.
  184.     jmp    do_next_old    ;Go back to do the next one.
  185.  
  186. exit:    pop    es        ;    for basic
  187.     pop    ds        ;    for basic
  188.     pop    bp        ;    for basic
  189.     ret    6        ;return to basic 3 parameters were sent
  190. ;
  191. MOVFILES  endp
  192. ;
  193.  
  194. ;---------------------------------------------------------------------
  195. mov_it    proc    near
  196. ;
  197. ;   move string from basic data area to local data area
  198. ;
  199. mov_st: mov    al,es:[si]    ;move character from basic to al
  200.     mov    ds:[di],al    ;move character to local data area
  201.     inc    si        ; increment
  202.     inc    di        ;   pointers
  203.     loop    mov_st        ; if cx<>0 then do next
  204. ;
  205.     ret
  206. mov_it    endp
  207. ;---------------------------------------------------------------------
  208. ;-----------------------------------------------------------------------
  209. cseg    ends
  210.     end            ;end of assembly
  211.